from django.db import models


# 新建出版社表
class PubName(models.Model):
    pubname = models.CharField('名称', max_length=255, unique=True)


class Author(models.Model):  # 创建作者表
    name = models.CharField(max_length=30, verbose_name='姓名')
    email = models.EmailField(verbose_name='邮箱')

    def __str__(self):
        return '作者：%s' % self.name


class Book(models.Model):  # 创建 book 表
    title = models.CharField(max_length=30, unique=True, verbose_name='书名')
    pub = models.ForeignKey("PubName", on_delete=models.CASCADE, null=True)
    authors = models.ManyToManyField("Author")

    def default_price(self):
        return '30'

    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='定价', default=default_price)
    retail_price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='零售价', default=default_price)

    def __str__(self):
        return "title:%s pub:%s price:%s" % (self.title, self.pub.pubname, self.price)


class UserInfo(models.Model):  # 创建用户信息表
    username = models.CharField(max_length=24, verbose_name='用户名')
    password = models.CharField(max_length=24, verbose_name='密码')
    # 定义choices参数的对应关系，以元组（或者列表）的形式进行表述：
    choices = (
        ('male', '男性'),
        ('female', '女性'),
    )
    gender = models.CharField(max_length=20, choices=choices, default='male')
    extendUserInfo = models.OneToOneField("ExtendUserinfo", on_delete=models.CASCADE)


# 新建一对一关用户信息表拓展表,添加完成后执行数据库迁移同步操作
class ExtendUserinfo(models.Model):
    signature = models.CharField(max_length=255, verbose_name='用户签名', help_text='自建签名')
    nickname = models.CharField(max_length=255, verbose_name='昵称', help_text='自建昵称')


class detection(models.Model):
    src_ip = models.CharField(max_length=255, verbose_name='源地址')
    src_port = models.CharField(max_length=255, verbose_name='源端口')
    dst_ip = models.CharField(max_length=255, verbose_name='目的地址')
    dst_port = models.CharField(max_length=255, verbose_name='目的端口')
    label = models.CharField(max_length=255, verbose_name='源标签')
